﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.admin
{
    public partial class WebForm14 : System.Web.UI.Page
    {
        private DataClasses1DataContext dc = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                show();
            }
            
        }

        private void show()
        {
            this.GridViewListUser.DataSource = dc.EmpRegisters;
            this.GridViewListUser.DataBind();
        }
       

        protected void GridViewListUser_PageIndexChanging1(object sender, GridViewPageEventArgs e)
        {
            GridViewListUser.PageIndex = e.NewPageIndex;
            show();
        }

        protected void GridViewListUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                Label labeluser = (Label)GridViewListUser.Rows[e.RowIndex].FindControl("LabeEmpno");
                int empno = Convert.ToInt32(labeluser.Text);
                using (DataClasses1DataContext dc = new DataClasses1DataContext())
                {
                    EmpRegister em = dc.EmpRegisters.Single(ee => ee.empno == empno);
                    //var user = dc.EmpRegisters.FirstOrDefault(u => u.empno == empno);
                    dc.EmpRegisters.DeleteOnSubmit(em);
                    dc.SubmitChanges();
                    show();
                }
            }
            catch(Exception)
            {
                this.Labelkothe.Text = "Khong the xoa";
            }
        }

    }
}